package com.enjoyor.soa.traffic.server.tpcms.dubbo.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.enjoyor.soa.traffic.api.dto.tpcms.RltBayonetZoneDto;
import com.enjoyor.soa.traffic.api.service.dubbo.tpcms.IDubboRltBayonetZoneService;
import com.enjoyor.soa.traffic.core.tpcms.domain.RltBayonetZone;
import com.enjoyor.soa.traffic.core.tpcms.service.IRltBayonetZoneService;
import com.enjoyor.soa.traffic.util.helper.ReflectHelper;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

@Service(version = "1.0.0", timeout = 4000)
public class DubboRltBayonetZoneService implements IDubboRltBayonetZoneService {

    @Autowired
    private IRltBayonetZoneService rltBayonetZoneService;

    /**
     * 获取关联卡口列表
     */
    @Override
    public ResultPojo getRltBayonetList(String relationId) {
        return new ResultPojo(rltBayonetZoneService.getRltBayonetList(relationId));
    }

    /**
     * 关联卡口
     */
    @Override
    public ResultPojo insertRltBayonet(List<RltBayonetZoneDto> rltBayonetZones, String username) {
        /*
         * for (RltBayonetZone rltBayonetZone : rltBayonetZones) {
         * rltBayonetZone.setRelationId(relationId); }
         */
        rltBayonetZoneService.insertRltBayonet(ReflectHelper.listToList(rltBayonetZones, RltBayonetZone.class),
                username);
        return new ResultPojo();
    }

    /**
     * 取关卡口
     */
    @Override
    public ResultPojo deleteRltBayonet(RltBayonetZoneDto rltBayonetZone, String username) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("relationId", rltBayonetZone.getRelationId());
        map.put("bayonetId", rltBayonetZone.getBayonetId());
        rltBayonetZoneService.deleteRltBayonet(map, username);
        return new ResultPojo();
    }

    /**
     * 单个卡口关联
     */
    @Override
    public ResultPojo insertRltBayonetForOne(RltBayonetZoneDto rltBayonetZone, String username) {
        rltBayonetZoneService.insertRltBayonetForOne(ReflectHelper.beanToBean(rltBayonetZone, RltBayonetZone.class),
                username);
        return new ResultPojo();
    }

}
